import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class EslPlayerGroup {
	public final static int MAXSIZE = 10;
	private HLPlayer[] group;
	private int size;
	private Pattern steamIDPattern;
	private String steamIDRegex = "[01]:[01]:[0-9]+";
	
	
	public EslPlayerGroup(String someIDs) throws IOException {
		size = 0;
		group = new HLPlayer[MAXSIZE];
		steamIDPattern = Pattern.compile(steamIDRegex);
		Matcher matcher = steamIDPattern.matcher(someIDs);
		while(matcher.find()){
			try{
				add(new EslPlayer(matcher.group()));
			}catch(EslAccountNotFoundException e){
				add(new NoESLPlayer(matcher.group()));
			}
			
		}
	}
	
	public void add(HLPlayer player){
		if(player == null)
			throw new NullPointerException();
		if(size >= MAXSIZE)
			throw new GroupIsFullException();
		group[size] = player;
		size++;
	}
	
	public String toString(){
		StringBuffer sb = new StringBuffer("<html><body>");
		for(int i=0;i<size;i++){
			sb.append(group[i]).append("<br>");
		}
		sb.append("</html></body>");
		return sb.toString();
	}
}
